using System;
using System.Windows;
using System.Data;
using System.Xml;
using System.Configuration;

namespace WPFPhysics1
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>

	public partial class App : System.Windows.Application
	{
        private int currentBodyId=0;

		public App()
		{
			Dispatcher.UnhandledException += Dispatcher_UnhandledException;
		}

        public String nextBodyId()
        {
            //roll over the body id. these should never collide

            if (currentBodyId == Int32.MaxValue)
            {
                currentBodyId = 0;
            }
            else
            {
                currentBodyId++;
            }
            return currentBodyId.ToString();
        }

		void Dispatcher_UnhandledException( object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e )
		{
			var ex = e.Exception;
			var message = "";

			while ( ex != null )
			{
				message += "\n  " + ex.Message;
				ex = ex.InnerException;
			}

			MessageBox.Show( string.Format( "An unhandled exception occurred; see Application log for details:{0}", message ) );
			e.Handled = false;
		}
	}
}